bit-bang UART implementation More...
#include "bit_bang_uart.h"#include "msp430x24x.h"Defines | |
| #define | MDB 1 |
| #define | BIT_BANG_TX_PORT P6OUT |
| #define | BIT_BANG_TX_BIT BIT7 |
| #define | BIT_BANG_RX_PORT P2IN |
| #define | BIT_BANG_RX_BIT BIT5 |
| #define | DISABLE_BIT_BANG_RX_INTERRUPT() (P2IE &= ~BIT5) |
| #define | ENABLE_BIT_BANG_RX_INTERRUPT() (P2IE |= BIT5) |
| #define | BIT_LENGTH_9600 160 |
| #define | HALF_BIT_LENGTH_9600 76 |
| #define | BIT_LENGTH_19200 75 |
| #define | HALF_BIT_LENGTH_19200 27 |
| #define | OUTPUT_1() (BIT_BANG_TX_PORT |= BIT_BANG_TX_BIT) |
| #define | OUTPUT_0() (BIT_BANG_TX_PORT &= ~BIT_BANG_TX_BIT) |
| #define | NUMBER_OF_DATA_BITS 8 |
| #define | TOGGLE_DEBUG_PIN() (P4OUT ^= BIT5) |
Functions | |
| void | delayFullBit () |
| void | delayHalfBit () |
| void | bitBangOutput (unsigned char outputByte) |
| char | bitBangInput () |
bit-bang UART implementation
This file implements a simple software defined Universal Asynchronous Receiver/Transmitter (UART). For simplicity and portability, timing is done using delay loops. Depending on hardware resources, you may want to use a timer instead.
Baud rate is 19200 in the format 8-N-1: 8 data bits, no parity, 1 stop bit. Line is normally high.
The defines will need to be modified if changing hardware implementation.
| char bitBangInput | ( | ) |
Blocking UART receiver. Called by BIT_BANG_RX_PORT Interrupt Service Routine upon detection of start bit (high to low transition). BIT_BANG_RX_BIT should be configured as high-low edge triggered interrupt. Receives a byte and then processes it.
| void bitBangOutput | ( | unsigned char | outputByte | ) |
Transmits one byte out the specified pin
| byte | the byte to output |
| void delayFullBit | ( | ) |
Simple delay for bit width. Used in transmit and receive.
| void delayHalfBit | ( | ) |
Simple delay for 1/2 of bit width. Used in receive.
1.6.3